function FeedbackView() {
	this.parent();
}

FeedbackView.inherits(BaseView, {
	init : function() {
		this.createView(this.ctrl.model.feedbacks);

	},
	createView : function(data) {
		var key = "feedback";
		addActive(key);
		var root = document.getElementById("loadFeedBack");
		root.innerHTML = "";
		if (data.length > 0) {
			var nodeTable = createTable();
			nodeTable.setAttribute("id", "tableFeedBack");

			var nodeThId = createNode("th");
			var idTh = createTextNode("Mã");
			nodeThId.appendChild(idTh);
			var nodeThTitle = createNode("th");
			var titleTh = createTextNode("Tiêu đề");
			nodeThTitle.appendChild(titleTh);
			var nodeThAcc = createNode("th");
			var accTh = createTextNode("Người gửi");
			nodeThAcc.appendChild(accTh);
			var nodeThDate = createNode("th");
			var dateTh = createTextNode("Ngày gửi");
			nodeThDate.appendChild(dateTh);
			var nodeThDetails = createNode("th");
			var nodeThDelete = createNode("th");

			nodeTable.appendChild(nodeThId);
			nodeTable.appendChild(nodeThTitle);
			nodeTable.appendChild(nodeThAcc);
			nodeTable.appendChild(nodeThDate);
			nodeTable.appendChild(nodeThDetails);
			nodeTable.appendChild(nodeThDelete);

			var nodeId = null;
			var nodeTitle = null;
			var nodeAcc = null;
			var nodeDate = null;

			var nodeDelete = null;
			var nodeTdDelete = null;
			var nodeDivDelete = null;

			for (var i = 0, j = data.length; i < j; i++) {
				var feedback = data[i];
				var row = document.createElement("tr");
				if (feedback.isReaded == "false") {
					row.className = "unread";
				}

				row.setAttribute("id", "feedbackIdInRow" + feedback.feedbackId);
				//cho từng column
				// <tr class="unread">
				// <td><a href="">1</a></td>
				// <td>Lam an nhu *beep*</td>
				// <td>Deptraikosoai</td>
				// <td>06/30/13</td>
				// <td><a href="">Chi tiết</a></td>
				// <td><a href="">Delete</a></td>
				// </tr>

				//column feedback id
				nodeId = document.createElement("td");
				var id = document.createTextNode(feedback.feedbackId);
				nodeId.appendChild(id);
				row.appendChild(nodeId);

				//cột tieu de

				nodeTitle = document.createElement("td");
				var title = document.createTextNode(feedback.title);
				nodeTitle.appendChild(title);
				row.appendChild(nodeTitle);

				// cột owner

				nodeAcc = document.createElement("td");
				var owner = document.createTextNode(feedback.email);
				nodeAcc.appendChild(owner);
				row.appendChild(nodeAcc);

				//cột order date

				nodeDate = document.createElement("td");
				var createTime = document.createTextNode(feedback.createTime);
				nodeDate.appendChild(createTime);
				row.appendChild(nodeDate);

				//cột detail
				var columnDetail = document.createElement("td");
				var divDetail = createDiv();
				divDetail.addClass("detailFeedback");
				var detail = document.createElement("span");
				detail.setText("Chi tiết");
				detail.style.cursor = "pointer";
				detail.style.color = "blue";
				divDetail.appendChild(detail);
				columnDetail.addEventListener("click", function() {
					var row = $id(event.currentTarget.parentNode.id);
					var cels = row.getElementsByTagName("td");
					var id = cels[0].innerText;
					getFeedbackDetails(id);
				});
				columnDetail.appendChild(divDetail);
				row.appendChild(columnDetail);

				//cot delete
				nodeTdDelete = createNode("td");
				nodeDivDelete = createDiv();
				nodeDelete = createNode("img");
				nodeDelete.setAttribute("src", Pages.params.img + "delete_icon.png");
				nodeDelete.style.cursor = "pointer";
				nodeTdDelete.addEventListener("click", function() {
					var row = $id(event.currentTarget.parentNode.id);
					var cels = row.getElementsByTagName("td");
					var feedbackId = cels[0].innerText;
					var r = confirm("Bạn có muốn xóa góp ý có mã là " + feedbackId + " ?");
					if (r == true) {
						deleteFeedback(feedbackId);
					}
				});
				nodeDivDelete.appendChild(nodeDelete);
				nodeTdDelete.appendChild(nodeDivDelete);
				row.appendChild(nodeTdDelete);

				nodeTable.appendChild(row);

			};
			root.appendChild(nodeTable);
			var divPaging = createDiv();
			divPaging.setAttribute("id", "pageFeedback");
			divPaging.setAttribute("class", "paging");
			var script = createNode("script");
			script.setAttribute("type", "text/javascript");
			script.innerHTML = "var pager = new Pager('tableFeedBack', 10); pager.init(); pager.showPageNav('pager', 'pageFeedback'); pager.showPage(1);";
			root.appendChild(divPaging);
			root.appendChild(script);
		}
	},
	
});

var FeedbackModel = function(id, email, title, content, createTime, isReaded) {
	this.id = id;
	this.email = email;
	this.title = title;
	this.content = content;
	this.createTime = createTime;
	this.isReaded = isReaded;
}
